use crate::config::run_setup::log_level::LogLevel;
use crate::config::run_setup::RUN_SETUP_CONFIG;
use chrono;


pub struct LogInfo {
  pub log_level: LogLevel,
  pub message: String,
  pub date_time: chrono::DateTime<chrono::Local>,
}

impl LogInfo {
  pub fn build(log_level: LogLevel, message: String) -> Self {
    if RUN_SETUP_CONFIG.get_is_print_log(&log_level) {
      println!("[{}]: {}", log_level.to_string(), message);
    }
    Self {
      log_level,
      message,
      date_time: chrono::Local::now(),
    }
  }

  pub fn build_error(message: String) -> Self {
    Self::build(LogLevel::Error, message)
  }

  pub fn build_info(message: String) -> Self {
    Self::build(LogLevel::Info, message)
  }

  pub fn build_dev(message: String) -> Self {
    Self::build(LogLevel::Dev, message)
  }

  pub fn is_should_print(&self) -> bool {
    RUN_SETUP_CONFIG.get_is_print_log(&self.log_level)
  }

  pub fn to_text(&self) -> String {
    let log_date_str = self.date_time.format("%Y-%m-%d %H:%M:%S").to_string();
    let log_level = self.log_level.to_string();
    let log_message = self.message.as_str();
    format!("-------[{log_level}]: {log_date_str}>>>>>>>>

{log_message}

<<<<<<<<[{log_level}]-------")
  }
}
